﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PolePosition.v3.Desktop.Selectors.Controls
{
    public partial class XMissionProperties : DialogEditBase
    {
        public XMissionProperties()
        {
            InitializeComponent();
            BindLists();
        }

        private void XMissionProperties_Load(object sender, EventArgs e)
        {

        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string SelectedKvList
        {
            get { return listSelectorKv.GetSelectedValueList<int>(); }
            set
            {
                listSelectorKv.SetSelectedValueList<int>(value);
                if (!listSelectorKv.AllItemsChecked)
                    checkBoxXViewAll.Checked = false;
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string SelectedTopTypeList
        {
            get { return listSelectorTopType.GetSelectedValueList<int>(); }
            set
            {
                listSelectorTopType.SetSelectedValueList<int>(value);
                if (!listSelectorTopType.AllItemsChecked)
                    checkBoxXViewAll.Checked = false;
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string SelectedClassList
        {
            get { return listSelectorPoleClass.GetSelectedValueList<int>(); }
            set
            {
                listSelectorPoleClass.SetSelectedValueList<int>(value);
                if (!listSelectorPoleClass.AllItemsChecked)
                    checkBoxXViewAll.Checked = false;
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string SelectedSpeciesList
        {
            get { return listSelectorPoleSpecies.GetSelectedValueList<int>(); }
            set
            {
                listSelectorPoleSpecies.SetSelectedValueList<int>(value);
                if (!listSelectorPoleSpecies.AllItemsChecked)
                    checkBoxXViewAll.Checked = false;
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string SelectedTreatmentList
        {
            get { return listSelectorPoleTreatment.GetSelectedValueList<int>(); }
            set
            {
                listSelectorPoleTreatment.SetSelectedValueList<int>(value);
                if (!listSelectorPoleTreatment.AllItemsChecked)
                    checkBoxXViewAll.Checked = false;
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string SelectedYearList
        {
            get { return listSelectorPoleYear.GetSelectedValueList<int>(); }
            set
            {
                listSelectorPoleYear.SetSelectedValueList<int>(value);
                if (!listSelectorPoleYear.AllItemsChecked)
                    checkBoxXViewAll.Checked = false;
            }
        }

        private void BindLists()
        {
            if (Program.LookupTableData != null)
            {
                listSelectorKv.DisplayMember = EntityLibrary.VendorVisitTypeEnumerations.Columns.Name.ToString();
                listSelectorKv.ValueMember = EntityLibrary.VendorVisitTypeEnumerations.Columns.Vendor_Visit_TypeId.ToString();
                listSelectorKv.DataSource = Program.LookupTableData.VendorVisitType;
                listSelectorKv.AddBlankOption<EntityLibrary.VendorVisitTypeEntity>();

                listSelectorTopType.DisplayMember = EntityLibrary.XMissionStructuresPoleTopTypeEnumerations.Columns.Name.ToString();
                listSelectorTopType.ValueMember = EntityLibrary.XMissionStructuresPoleTopTypeEnumerations.Columns.XMissionStructures_PoleTopTypeId.ToString();
                listSelectorTopType.DataSource = Program.LookupTableData.XMissionStructuresPoleTopTypes;
                listSelectorTopType.AddBlankOption<EntityLibrary.XMissionStructuresPoleTopTypeEntity>();

                listSelectorPoleClass.DisplayMember = EntityLibrary.XMissionStructuresPoleClassesEnumerations.Columns.Name.ToString();
                listSelectorPoleClass.ValueMember = EntityLibrary.XMissionStructuresPoleClassesEnumerations.Columns.XMissionStructures_PoleClassId.ToString();
                listSelectorPoleClass.DataSource = Program.LookupTableData.XMissionStructuresPoleClasses;
                listSelectorPoleClass.AddBlankOption<EntityLibrary.XMissionStructuresPoleClassesEntity>();

                listSelectorPoleSpecies.DisplayMember = EntityLibrary.XMissionStructuresPoleSpeciesEnumerations.Columns.Name.ToString();
                listSelectorPoleSpecies.ValueMember = EntityLibrary.XMissionStructuresPoleSpeciesEnumerations.Columns.XMissionStructures_PoleSpeciesId.ToString();
                listSelectorPoleSpecies.DataSource = Program.LookupTableData.XMissionStructuresPoleSpecies;
                listSelectorPoleSpecies.AddBlankOption<EntityLibrary.XMissionStructuresPoleSpeciesEntity>();

                listSelectorPoleTreatment.DisplayMember = EntityLibrary.XMissionStructuresPoleTreatmentEnumerations.Columns.Name.ToString();
                listSelectorPoleTreatment.ValueMember = EntityLibrary.XMissionStructuresPoleTreatmentEnumerations.Columns.XMissionStructures_PoleTreatmentId.ToString();
                listSelectorPoleTreatment.DataSource = Program.LookupTableData.XMissionStructuresPoleTreatments;
                listSelectorPoleTreatment.AddBlankOption<EntityLibrary.XMissionStructuresPoleTreatmentEntity>();

                listSelectorPoleYear.DisplayMember = "Text";
                listSelectorPoleYear.ValueMember = "Value";
                listSelectorPoleYear.DataSource = ComboOptions.PoleYears;
                listSelectorPoleYear.AddBlankOption<Common.BindingLists.ListItem>();

                SetListsEnabled();
            }
        }

        private void checkBoxXViewAll_CheckedChanged(object sender, EventArgs e)
        {
            SetListsEnabled();
        }

        private void SetListsEnabled()
        {
            bool _Enabled = !checkBoxXViewAll.Checked;

            foreach (Control _List in panelSelectors.Controls)
            {
                (_List as ListSelector).Enabled = _Enabled;
            }
        }
    }
}
